package com.yn.service.zy.model.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yn.common.model.zy.DeviceRentOrderDetailDO;
import com.yn.common.utils.BeanUtils;
import com.yn.common.utils.MoneyUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @ClassName: DeviceRentOrderDetailDTO
 * @Description: 设备订单详情DTO
 * @Author: ym
 * @Date: 2025/5/10 9:29
 **/
@Data
public class DeviceRentOrderDetailDTO {
    /** 订单详情id */
    @ApiModelProperty(value = "订单详情id")
    private Integer id;
    /** 设备租聘订单id */
    @ApiModelProperty(value = "设备租聘订单id")
    private Integer deviceRentOrderId;
    /** 设备id */
    @ApiModelProperty(value = "设备id")
    private Integer deviceId;
    /** 租赁天数 */
    @ApiModelProperty(value = "租赁天数")
    private Integer rentDay;
    /** 设备租金 */
    @ApiModelProperty(value = "设备租金")
    private BigDecimal deviceRent;
    /** 设备押金 */
    @ApiModelProperty(value = "设备押金")
    private BigDecimal equipmentDeposit;
    /** 佣金 */
    @ApiModelProperty(value = "佣金")
    private BigDecimal commissionMoney;
    /** 积分 */
    @ApiModelProperty(value = "积分")
    private Integer commissionPoints;
    /** 创建时间 */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    public static DeviceRentOrderDetailDO transform(DeviceRentOrderDetailDTO deviceRentOrderDetailDTO) {
        if (Objects.isNull(deviceRentOrderDetailDTO)){
            return null;
        }

        DeviceRentOrderDetailDO deviceRentOrderDetailDO = BeanUtils.copyProperties(deviceRentOrderDetailDTO, DeviceRentOrderDetailDO.class);

        if (Objects.nonNull(deviceRentOrderDetailDTO.getDeviceRent())){
            deviceRentOrderDetailDO.setDeviceRent(MoneyUtils.yuan2fen(deviceRentOrderDetailDTO.getDeviceRent()));
        }
        if (Objects.nonNull(deviceRentOrderDetailDTO.getEquipmentDeposit())){
            deviceRentOrderDetailDO.setEquipmentDeposit(MoneyUtils.yuan2fen(deviceRentOrderDetailDTO.getEquipmentDeposit()));
        }
        if (Objects.nonNull(deviceRentOrderDetailDTO.getCommissionMoney())){
            deviceRentOrderDetailDO.setCommissionMoney(MoneyUtils.yuan2fen(deviceRentOrderDetailDTO.getCommissionMoney()));
        }
        return deviceRentOrderDetailDO;
    }


    public static DeviceRentOrderDetailDTO transform(DeviceRentOrderDetailDO deviceRentOrderDetailDO) {
        if (Objects.isNull(deviceRentOrderDetailDO)){
            return null;
        }
        DeviceRentOrderDetailDTO deviceRentOrderDetailDTO = BeanUtils.copyProperties(deviceRentOrderDetailDO, DeviceRentOrderDetailDTO.class);

        if (Objects.nonNull(deviceRentOrderDetailDO.getDeviceRent())){
            deviceRentOrderDetailDTO.setDeviceRent(MoneyUtils.fen2yuan(deviceRentOrderDetailDO.getDeviceRent()));
        }
        if (Objects.nonNull(deviceRentOrderDetailDO.getEquipmentDeposit())){
            deviceRentOrderDetailDTO.setEquipmentDeposit(MoneyUtils.fen2yuan(deviceRentOrderDetailDO.getEquipmentDeposit()));
        }
        if (Objects.nonNull(deviceRentOrderDetailDO.getCommissionMoney())){
            deviceRentOrderDetailDTO.setCommissionMoney(MoneyUtils.fen2yuan(deviceRentOrderDetailDO.getCommissionMoney()));
        }
        return deviceRentOrderDetailDTO;
    }
}
